#ifndef WAVESHARE_LCD_146_BOARD_H
#define WAVESHARE_LCD_146_BOARD_H

#include "display/lcd_display.h"
#include "button.h"
#include "config.h"
#include "common/backlight.h"

class CustomLcdDisplay : public SpiLcdDisplay {
public:
    static void rounder_event_cb(lv_event_t * e);
    
    CustomLcdDisplay(esp_lcd_panel_io_handle_t io_handle, 
                   esp_lcd_panel_handle_t panel_handle,
                   int width,
                   int height,
                   int offset_x,
                   int offset_y,
                   bool mirror_x,
                   bool mirror_y,
                   bool swap_xy);
};

class CustomBoard {
private:
    i2c_master_bus_handle_t i2c_bus_;
    esp_io_expander_handle_t io_expander;
    LcdDisplay* display_;
    button_handle_t boot_btn, pwr_btn;
    button_driver_t* boot_btn_driver_;
    button_driver_t* pwr_btn_driver_;
    static CustomBoard* instance_;

    void InitializeI2c();
    void InitializeTca9554();
    void InitializeSpi();
    void InitializeSpd2010Display();
    void InitializeButtonsCustom();
    void InitializeButtons();
    
public:
    CustomBoard();
    static CustomBoard& GetInstance();
    Display* GetDisplay();
    Backlight* GetBacklight();
};

void* create_board();

#define DECLARE_BOARD(BOARD_CLASS_NAME) \
void* create_board() { \
    return new BOARD_CLASS_NAME(); \
}

#endif // WAVESHARE_LCD_146_BOARD_H
